#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    long long calculateScore(vector<string>& instructions, vector<int>& values) 
    {
        long long ret = 0;
        set<int> isused;
        for(int i = 0;i<instructions.size();)
        {
            if(instructions[i] == "add"&&isused.find(i) == isused.end())
            {
                ret+=values[i];
                isused.insert(i);
                i++;
            }
            else if(instructions[i] == "jump"&&isused.find(i) == isused.end())
            {
                isused.insert(i);
                i+=values[i];
            }
            else
            {
                break;
            }
        }
        return ret;
    }
};